package com.bito.aiot.admin.controller.websocket;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;

import javax.websocket.EncodeException;
import javax.websocket.Encoder;
import javax.websocket.EndpointConfig;
import java.util.HashMap;

/**
 * @author 小木
 * @date 2022/9/23
 */
@Slf4j
public class ServerEncoder implements Encoder.Text<Object> {
    @Override
    public String encode(Object message) throws EncodeException {
        try {
            return JSONObject.toJSONString(message);
        } catch (Exception e) {
            log.error("解码器异常: {}", e.getMessage());
        }
        return null;
    }

    @Override
    public void init(EndpointConfig endpointConfig) {

    }

    @Override
    public void destroy() {

    }
}
